#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import model
import argparse

from model.readers.toquinsqlite3reader import ToquinSqlite3Reader

sys.path.append("third-party/metalink-library")

import metalink

def main():
    reader = ToquinSqlite3Reader()
    model.current_model = reader.read("Toquin.db")
    m = metalink.Metalink()

    for i in model.current_model.getItems():
        if not i.url:
            continue

        if len(m.files) > 0:
            m.add_file()

        m.add_url(i.url)

    print m.generate()

if __name__ == "__main__":
    main()
